import '../../core/service_locator.dart';
import '../../models/user_model.dart';
import '../../core/http_client.dart';

class AuthService {
  final HttpClient _http = ServiceLocator.httpClient; // 修改这一行

  Future<User> login(String email, String password) async {
    final response = await _http.post(
      '/auth/login',
      data: {'email': email, 'password': password},
    );
    return User.fromJson(response.data);
  }

  Future<User> register(String email, String password, String username) async {
    final response = await _http.post(
      '/auth/register',
      data: {'email': email, 'password': password, 'username': username},
    );
    return User.fromJson(response.data);
  }

  Future<User> getProfile() async {
    final response = await _http.get('/user/profile');
    return User.fromJson(response.data);
  }

  Future<void> logout() async {
    await _http.post('/auth/logout');
    // 清除本地token
  }
}
